﻿@model NC.Cather.ContentParams
@{
    ViewBag.Title = "Create";
}

<script src="~/Content/IsLoading/jquery.isloading.min.js"></script>
<link href="~/Content/IsLoading/isloading.css" rel="stylesheet" />
<section class="content-header">
    <h1>
        文章内容参数管理
        <small>13 new messages</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="@Url.Action("Index")"><i class="fa fa-dashboard"></i>首页</a></li>
        <li class="active">添加</li>
    </ol>
</section>
<section class="content">
    <div class="row">
        <div class="col-md-6">
            <div class="box box-solid">
                <div class="box-body">
                    @using (Html.BeginForm())
                    {
                        @Html.AntiForgeryToken()
                        <div class="form-horizontal">
                            @Html.ValidationSummary(true, "", new { @class = "text-danger" })
                            @Html.Partial("Form")
                            <div class="form-group">
                                <div class="col-md-offset-2 col-md-4">
                                    <input type="submit" value="创建" class="btn btn-primary" />
                                </div>
                                <div class="col-md-offset-2 col-md-4">
                                    <input type="button" value="测试" onclick="contentTest()" class="btn btn-success" />
                                </div>
                            </div>
                        </div>
                    }
                </div>
            </div>
        </div>
        <div class="col-md-6">
            <div class="box box-solid">
                <div class="box-body">
                    <div class="form-horizontal">
                        <div class="form-group">
                            <label class="control-label col-md-2">标题</label>
                            <div class="col-md-10">
                                <input type="text" id="TitleSelectorN" class="form-control" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-md-2">作者选择器</label>
                            <div class="col-md-10">
                                <input type="text" id="AuthorSelectorN" class="form-control" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-md-2">出版日期</label>
                            <div class="col-md-10">
                                <input type="text" id="ComeUpTimeSelectorN" class="form-control" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-md-2">文章类型选择</label>
                            <div class="col-md-10">
                                <input type="text" id="TypeSelectorN" class="form-control"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-md-2">文章详情</label>
                            <div class="col-md-10">
                                <textarea  id="ContentSelectorN" class="form-control" rows="20"></textarea>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</section>
<script type="text/javascript">
    function checkUrlIsValide() {
        var url = $("#TestUrl").val();
        $.ajax({
            url: "@Url.Action("CheckUrl","Target")",
            data: { url: url },
            type: "post",
            success: function (data) {
                if (data.status == 0) {
                    showError(data.msg);
                }
            },
            error: function (error) {
                showError("服务器出错");
            }
        });
    }
    function contentTest() {
        var entity = {};
        var ids = ["ContainerSelector", "TitleSelector", "AuthorSelector", "ComeUpTimeSelector", "ContentSelector", "TypeSelector", "TestUrl"];
        for (var i = 0; i < ids.length; i++) {
            var data = getDataById(ids[i]);
            if (data.status == 0) {
                showError(data.msg);
                return;
            }
            entity[ids[i]] = data.msg;
        }
        $.isLoading({ text: "Loading" });
        $.ajax({
            url: "@Url.Action("GetTestContent")" + "?testUrl=" + entity.TestUrl,
            type: "post",
            data: { entity: entity },
            success: function (d) {
                $.isLoading("hide");
                var data = JSON.parse(d);
                if (data.status == 0) {
                    showError(data.msg);
                } else {
                    console.log(data.msg);
                    setArticleContent(data.msg);
                }
            },
            error: function (error) {
                $.isLoading("hide");
                showError("服务器出错");
            }
        });
    }
    function setArticleContent(data) {
        console.log(data);
        for (i in data) {
            if (i != "ContainerSelector") {
                $("#" + i + "N").val(data[i]);
            }
        }
    }
    function getDataById(id) {
        var data = $("#" + id).val();
        if (data == "" || data == undefined) {
            return { status: 0, msg: $("#" + id).parent().parent().find("label").html() + "不能为空" };
        } else {
            return { status: 1, msg: data };
        }
    }
</script>
